//
//  CRBRotateBoxCustomItemCell.m
//  ChampsARotate
//
//  Created by Login.Fan on 2018/11/1.
//  Copyright © 2018 Logan.Fan. All rights reserved.
//

#import "CRBRotateBoxCustomItemCell.h"

@interface CRBRotateBoxCustomItemCell ()

@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UILabel *brandCNLabel;
@property (weak, nonatomic) IBOutlet UILabel *brandENLabel;
@property (weak, nonatomic) IBOutlet UILabel *seriesLabel;

@end


@implementation CRBRotateBoxCustomItemCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.brandCNLabel.hidden = YES;
    self.brandENLabel.hidden = YES;
    self.seriesLabel.hidden = YES;
    
    [self cellSelectes:NO];
}

- (void)drawRect:(CGRect)rect {
//    [self.bgView viewAddRounderCornerWithRadius:8 borderWidth:2 borderColor:UIColor.fontColorDarkGrey];

[self viewAddRounderCornerWithRadius:8 borderWidth:2 borderColor:[UIColor RGBColorWithR:51 g:51 b:51] view:self.bgView];
}

- (void)viewAddRounderCornerWithRadius:(CGFloat)radius borderWidth:(CGFloat)width borderColor:(UIColor *)color view:(UIView*)view {
    
    UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, view.mj_w, view.mj_h) cornerRadius:radius];
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    
    if (radius != 0) {
        maskLayer.path = bezierPath.CGPath;
    }
    maskLayer.frame = CGRectMake(0, 0, view.mj_w, view.mj_h);
    
    if (width != 0 && color) {
        CAShapeLayer *borderLayer = [CAShapeLayer layer];
        borderLayer.frame = CGRectMake(0, 0, view.mj_w, view.mj_h);
        borderLayer.lineWidth = width;
        borderLayer.strokeColor = color.CGColor;
        borderLayer.fillColor = [UIColor clearColor].CGColor;
        borderLayer.path = bezierPath.CGPath;
        [view.layer insertSublayer:borderLayer atIndex:0];
    }
    [view.layer setMask:maskLayer];
}


#pragma mark - 私有方法
/** 品牌*/
- (void)showChooseBrandStyle {
    self.brandENLabel.hidden = NO;
    self.brandCNLabel.hidden = NO;
}

/** 系列*/
- (void)showChooseSeriesStyle {
    self.seriesLabel.hidden = NO;
}

/** 是否选择*/
- (void)cellSelectes:(BOOL)select {
    self.brandCNLabel.textColor = select ? UIColor.whiteColor : [UIColor RGBColorWithR:51 g:51 b:51];
    self.brandENLabel.textColor =  select ? UIColor.whiteColor : [UIColor RGBColorWithR:51 g:51 b:51];
    self.seriesLabel.textColor =  select ? UIColor.whiteColor : [UIColor RGBColorWithR:51 g:51 b:51];
    self.bgView.backgroundColor = select ? [UIColor RGBColorWithR:51 g:51 b:51] : UIColor.whiteColor;
}

#pragma mark - 外部方法

#pragma mark - Model

- (void)setBrandInfoModel:(BrandInfoModel *)model {
     [self showChooseBrandStyle];
    self.brandCNLabel.text = [NSString stringWithFormat:@"%@",model.brandNameNative];
    self.brandENLabel.text = [NSString stringWithFormat:@"%@",model.brandName];
}

/** 加载系列数据模型 **/
- (void)setSeriesInfoModel:(CRBSeriesInfoModel *)model {
    [self showChooseSeriesStyle];
    self.seriesLabel.text = [NSString stringWithFormat:@"%@",model.seriesName];
}
- (void)setGoodsInfoModel:(goodVOsModel *)model {
    [self showChooseSeriesStyle];
    self.seriesLabel.text = [NSString stringWithFormat:@"%@",model.goodInfo.goodName];
}
@end
